package com.ryl.yomall.model.common.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @Date 15:48
 * @Author ryl
 * 远程调用拦截器工具类
 */

public class LogoutInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //1:当前请求对象头中用户ID 传递给 远程调用请求对象的头中
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes ( );
//        if(requestAttributes !=null){
//            //当前微服务的请求对象
//            HttpServletRequest request = requestAttributes.getRequest ( );
//            if(request != null){
//                Cookie[] cookies = request.getCookies ( );
//                if(cookies !=null &&cookies.length>0){
//                    for (Cookie cookie : cookies) {
//                        if("token".equals ( cookie.getName () )){
//                            String token=cookie.getValue ();
//                            requestTemplate.header ( "token",token );
//                        }
//                    }
//                }
//
//            }
//        }
    }
}
